package domain

import (
	"github.com/lab-online/internal/class/constant"
	"github.com/lab-online/internal/class/entity"
	"github.com/lab-online/internal/shared/code"
	"github.com/lab-online/pkg/auth"
)

func (d *Domain) UpdateClass(
	classEntity entity.ClassEntity,
	authEntity auth.AuthEntity,
) error {
	if !classEntity.CanHandleClass(authEntity, false) {
		return constant.RESTErrNoPermissionToCreateClass
	}

	if _, err := d.repository.SaveClass(classEntity); err != nil {
		return code.ErrorPicker(err, code.DatabaseClassNotFound, constant.DBErrClassNotFound)
	}

	return nil
}
